//
//  TestTableVM.m
//  jhf
//
//  Created by 计海峰 on 2020/7/15.
//  Copyright © 2020 jhfappkf@163.com. All rights reserved.
//

#import "TestTableVM.h"
#import "RowImageBaseM.h"
#import "TableVCVM+RowCell.h"
#import "RowUploadImagesM.h"

@interface TestTableVM ()<TableConfigProtocol>

@end

@implementation TestTableVM

- (void)initDown {
    
}

- (void)show:(id)bind {
    
}

- (void)method:(id)bind {
    
}

- (void)labelShow:(id)any {
    NSLog(@"%@", any);
}

- (void)rowBTTap:(id)any {
    
    NSLog(@"%@", [self checkSumbitRow]);
    NSLog(@"%@", [self checkSumbitRowOutHint]);
    NSLog(@"%@", [self currentParams]);
    
    self.bindTargetVC.navigationItem.title = @"扯淡的人生";
    
    routerToByRowsVM(@"TestImagesTableVM", @"是吗？");
    
//    [TZImageTool addPhotosOrSingleVideoMaxNum:4 selectedAssets:nil andTarget:nil videoQuality:nil andBlock:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
//
//    } andSingleVideo:^(UIImage *coverImage, id asset) {
//
//    }];
//    [TZImageTool addVideosWithTarget:nil maxCount:4 videoBlock:^(NSArray<UIImage *> *coverImage, NSArray *assets, NSArray<NSDictionary *> *infos) {
//
//    }];
    
//    [TZImageTool addPhotosOrVideoMaxNum:9 selectedAssets:nil andTarget:nil andBlock:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
//
//    } andSingleVideo:^(UIImage *coverImage, id asset) {
//
//    }];
//    [[TZImageTool shared] addSinglePhotoWithClipping:false andTarget:nil andBLock:^(NSInteger idx, NSObject * _Nullable value) {
//        ImageControlM *control = [ImageControlM defaultIMGSource:(UIImage *)value];
//        control.vMasksToBounds = true;
//        control.isReal = true;
//        RowImageBaseM *baseV = [RowImageBaseM defaultControl:control];
//        baseV.bgVMarging = UIEdgeInsetsMake(4, 4, 4, 4);
//        [self.rows addObject:[self imageShowRow:baseV]];
//    }];
}

- (void)back:(id)any {
    navBack();
}


+ (RowInputBaseM *)inputTitle:(NSString *)title dataKey:(NSString *)dataKey {
    RowInputBaseM *inputControl = [RowInputBaseM defaultConfigTitle:title value:@""];
    inputControl.inputControl.textTextAlignment = NSTextAlignmentRight;
    
    inputControl.dataKey = dataKey;
    inputControl.optionData = false;
    
    return inputControl;
}

+ (RowInputBaseM *)inputTitle:(NSString *)title dataKey:(NSString *)dataKey line:(BOOL)line {
    RowInputBaseM *inputControl = [TestTableVM inputTitle:title dataKey:dataKey];
    if (line) {
        inputControl.bottomLineControl.vHeightCons = 0.5;
        inputControl.bottomLineControl.vBgColorHex = @"#CCCCCC";
        inputControl.bottomLineControl.vLeftCons = 15;
        inputControl.bottomLineControl.vRightCons = -15;
    }
    return inputControl;
}

+ (RowTitleBaseM *)showTitle:(NSString *)title dataKey:(NSString *)dataKey line:(BOOL)line {
    RowTitleBaseM *titleC = [RowTitleBaseM defaultWithTitleStr:@"测试"];
    titleC.dataKey = dataKey;
    titleC.optionData = false;
    if (line) {
        titleC.bottomLineControl.vHeightCons = 0.5;
        titleC.bottomLineControl.vBgColorHex = @"#CCCCCC";
        titleC.bottomLineControl.vLeftCons = 15;
        titleC.bottomLineControl.vRightCons = -15;
    }
    return titleC;
}

- (void)year_select:(BindModel *)bind {
//    bind.data = @{@"year_select": @"12", @"year_out": @"141"}.mutableCopy;
    RowTitleBaseM *titleC = bind.model;
    titleC.value = @"测试值";
    [bind.data setValue:@"12" forKey:@"year_out"];
    titleC.rightLBControl = [LabelControlM defaultText:@"测试值"];
    [bind.additionData setValue:@"additionData Value1" forKey:@"additionData"];
    [bind.action runService:ReloadRow any:bind.action.key];
}

- (void)forRows {
    NSMutableArray *rows = [NSMutableArray array];
    
    RowTitleBaseM *textControl = [RowTitleBaseM defaultWithTitleStr:@"仲达啊~仲达啊~仲达啊~仲达啊~仲达啊~仲达啊~仲达啊~仲达啊~仲达啊~仲达啊~仲达啊~仲达啊~仲达啊~仲达啊~仲达啊~仲达啊~仲达啊~仲达啊~仲达啊~仲达啊~仲达啊~仲达啊~仲达啊~仲达啊~"];
    textControl.titleLBControl.lines = 0;
    textControl.titleLBControl.textStrFont = [UIFont systemFontOfSize:15 weight:UIFontWeightMedium];
    textControl.titleLBControl.vBgColor = [UIColor redColor];
    textControl.titleLBControl.vLeftCons = 4;
    textControl.titleLBControl.vTopCons = 4;
    textControl.titleLBControl.vBottomCons = 4;
    textControl.titleLBControl.vRightCons = 4;
    textControl.titleLBControl.textTextAlignment = NSTextAlignmentCenter;
    Row *txtRow = [self textRow:textControl];
    txtRow.bgColorHex = @"#f5f6f7";
    [rows addObject:txtRow];
    
    [rows addObject:[self lineClearRow:12]];
    
    [rows addObject:[self inputTFRow:[TestTableVM inputTitle:@"年限" dataKey:@"year" line:true]]];
    
    RowTitleBaseM *testC = [TestTableVM showTitle:@"年限选择" dataKey:@"year_select" line:true];
    testC.methodFromKey = true;
    testC.needKeys = @[@"year_select", @"year_out"];
    testC.needKeysHintVals = @[@"请选择年限", @"请选择过期年限"];
    [rows addObject:[self imageTextRow:testC]];
    
//    RowTitleBaseM *avatarM = [RowTitleBaseM defaultWithTitleStr:@"头像"];
//
//    avatarM.titleLBControl.vTopCons = 18;
//
//    avatarM.rightImgControl = [ImageControlM defaultIMGName:@"icon_func_rightarrow"];
//    avatarM.rightImgControl.vRightCons = 12;
//    avatarM.rightImgControl.vBgColorHex = @"#ff6677";
//
//    avatarM.rightLeftImgControl = [ImageControlM defaultIMGUrl:@"https://dss1.bdstatic.com/kvoZeXSm1A5BphGlnYG/skin_zoom/320.jpg"];
//    avatarM.rightLeftImgControl.vWidthCons = 44;
//    avatarM.rightLeftImgControl.vHeightCons = 44;
//    avatarM.rightLeftImgControl.vMasksToBounds = true;
//
//    avatarM.bgControl.vBgColorHex = @"#f5f6f7";
//    [rows addObject:[self imageTextRow:avatarM]];
//
//    RowUploadImagesM *uplaod = [RowUploadImagesM defaultAddImageName:@"btn_add" dataKey:@"files"];
//    CGFloat cellW = (kScreen_Width - 40)/4.0;
//    uplaod.cellSize = CGSizeMake(cellW, cellW);
//    uplaod.numberOfVertail = 1;
//    uplaod.numberOfVertail = 4;
//    uplaod.sectionInset = UIEdgeInsetsMake(8, 8, 8, 8);
//    uplaod.deleteImage = @"evaluate_btn_delete";
//    [rows addObject:[self imagesPickerRow:uplaod]];
    
    NSMutableArray <ImageControlM *>*arrays = [NSMutableArray array];
    NSMutableArray *urls = [NSMutableArray array];
    NSMutableArray *sourceArray = @[
        @"https://dss1.bdstatic.com/kvoZeXSm1A5BphGlnYG/skin_zoom/320.jpg",
        @"https://dss1.bdstatic.com/kvoZeXSm1A5BphGlnYG/skin_zoom/321.jpg",
        @"https://dss1.bdstatic.com/kvoZeXSm1A5BphGlnYG/skin_zoom/322.jpg",
    ].mutableCopy;
    
    double totalWidth = (kScreen_Width - 56 - 30) - 16;
    double imageWidth = totalWidth * 0.68;
    NSInteger maxColumns = 1;
    if (sourceArray.count > 4) {
        imageWidth = totalWidth/3.0 - 0.1;
        maxColumns = 0;
    }else if (sourceArray.count > 1) {
        imageWidth = totalWidth * 0.45;
        maxColumns = 2;
    }
    
    [sourceArray enumerateObjectsUsingBlock:^(NSString * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        [urls addObject:obj];
        ImageControlM *controlIMG = [ImageControlM defaultIMGUrl:obj];
        controlIMG.vRadius = 4;
        controlIMG.vMasksToBounds = true;
        controlIMG.vTopCons = 4;
        controlIMG.vLeftCons = 4;
        controlIMG.vBottomCons = 4;
        controlIMG.vWidthCons = imageWidth;
        controlIMG.vHeightCons = imageWidth;
        controlIMG.imagePlaceholder = @"icon_logo";
        [arrays addObject:controlIMG];
    }];
    [arrays enumerateObjectsUsingBlock:^(ImageControlM * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        obj.imageUrls = urls;
    }];
    RowImagesBaseM *imageRowModel = [RowImagesBaseM defaultControls:arrays maxWidth:kScreen_Width - 86 numerOfColumn:maxColumns];
    imageRowModel.bgVMarging = UIEdgeInsetsMake(0, 56, 0, 30);
    imageRowModel.numerOfColumn = 2;
    Row *row = [self imagesShowRow:imageRowModel];
    if (imageRowModel.cellHeight > 0) {
        row.height = imageRowModel.cellHeight;
    }
    [rows addObject:row];
    
    [rows addObject:[self btnsShowRow:@[[ButtonControlM defaultBTText:@"提交"]]]];
    
//    ButtonControlM *backBT = [ButtonControlM defaultBTText:@"返回"];
//    backBT.method = @"back";
//    [rows addObject:[self btnsShowRow:@[backBT]]];
//
    [self.rows removeAllObjects];
    [self.rows addObjectsFromArray:rows];
    [self.rows addObjectsFromArray:rows];
    [self.rows addObjectsFromArray:rows];
    [self.rows addObjectsFromArray:rows];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self.rows addObjectsFromArray:rows];
        [self.rows addObjectsFromArray:rows];
        [self.rows addObjectsFromArray:rows];
        [self.rows addObjectsFromArray:rows];
    });
}

- (void)imageCellTap:(id)any {
    NSLog(@"%@", any);
}

@end
